

a = int(input("请输入一个整数: "))
if a % 2 == 0:
    print("偶数")
else:
    print("奇数")


 b = int(input("请输入一个数: "))
 if a > 0:
    print("正数")
elif a < 0:
    print("负数")
else:
    print("0")


year = int(input("请输入年份: "))
if year % 100 == 0:
    if year % 400 == 0:
        print("闰年")
    else:
        print("平年")
else:
    if year % 4 == 0:
        print("闰年")
    else:
        print("平年")


num = 1
while num <= 10:
    print(num)
    num += 1


sum = 0
num = 1
while num <= 100:
    sum += num
    num += 1
print(sum)


result = 1
n = 1
while n <= 5:
    result *= n
    n += 1
print(result)


sum = 0
num = 1
while num <= 5:
    fac = 1
    i = 1
    while i <= num:
        fac *= i
        i += 1
    sum += fac
    num += 1
print(sum)


for  i in range(2, 12, 2):
    print(i)

for i in range(10, 0, -1):
    print(i)

sum = 0
for i in range(1, 101):
    sum += i
print(sum)

def calSum(beg, end):
    sum = 0
    for i in range(beg, end+1):
        sum += i
    print(sum)

calSum(1, 100)
calSum(300, 400)
calSum(1, 1000)


def IsOdd(num):
    if num % 2 == 0:
        return False
    else:
        return True

result = IsOdd(10)
print(result)


def getPoint():
    x = 10
    y = 20
    return x,y

_, b = getPoint()


x = 20

def test():
    global x
    x = 10
    print(f'函数内部 x = {x}')


test()
print(f'函数外部 x = {x}')


def add(x, y, debug = False)
    if debug:
        print(f"调试消息是: x = {x}, y={y}")
    return x + y

alist = []

alist = list()

print(type(alist))

a = [1, 2, 3, 4]

b = [1, 'hello', True]

print(a[2])
a[2] = 100
print(a)

print(len(a))
print(a[-1])

print(a[1:3])

print(a[1:])
print(a[:-1])
print(a[:])


for elem in a:
    print(elem)

for i in range(0, len(a)):
    print(a[i])


def fac(n):
    if n == 1:
        return 1
    return fac(n-1)*n

result = fac(5)
print(result)


def add(x, y, debug=False):
    if debug:
        print(f'调试信息: x={x}, y={y}')
    return x + y

print(add(10, 20))
print(add(10, 20, True))


a = [1, 2, 3, 4]
a.append('hello')
print(a)

a.insert(1, 'hello')
print(a)

print(2 in a)
print(10 in a)

print(a.index(2))
print(a.index(10))#抛异常

a.pop()
a.pop(2)

a.remove(2)#删除值2

b = [5, 6, 7]
print(a + b)


a.extend(b)
print(a)
print(b)

atuple = ()
Tuple = tuple()

def get():
    return 10, 20

result = get()
print(type(result))


a = {}
b = dict()

print(type(a))
print(typr(b))

student = {'id' : 1, 'name' : 'zhangsan'}
print(student)

print('id' in student)
print(student['id'])

student['score'] = 90
print(student)

student.pop('score')#删除对应键值对;

for key in student:
    print(key, student[key])

print(student.keys())

print(student.values())

print(student.item())

f = open('d:/test.txt', 'w')
f.write('hello')
f.close()

f = open('d:/test.txt', 'r')
result = f.read(2)
print(result)
f.close()


f = open('d:/test.txt', 'r')
for i in f:
    print(f'line = {i}')
f.close()

f = open('d:/test.txt', 'r')
lines = f.readlines()
print(lines)
f.close()


with open('D:/test.txt', 'r', encoding='utf8') as f:
    lines = f.readlines()
    print(lines)

import datetime
date1 = datetime.datetime(2012, 2, 14)
date2 = datetime.datetime(2025, 1, 29)

print(date2 - date1)

def reversewords(s):
    tokens = s.split()
    tokens.reverse()
    return ' '.join(tokens)

print(reversewords('i am a student'))

def rotatestring(s, goal):
    return len(s) == len(goal) and goal in s + score

print(rotatestring('abcde', 'cdeab'))


def count(words, s):
    res = 0
    for word in words:
        if s.startswith(world)
            res += 1
    return res
print(count(['a', 'b', 'c', 'ab', 'bc', 'abc'], 'abc'))
